import { reqGetDetail, reqPostShopCart } from '@/api/index'
import userTemp from '@/utils/userTemp_token';
const actions = {
    async getDetail(context, skuId) {
        let result = await reqGetDetail(skuId)
        if (result.code == '200') {
            context.commit('GETDETAIL', result.data)
        }
    },
    //商品个数添加到购物车，发送网络请求
    async addOrUpdateShopCart(context, { skuId, skuNum }) {
        //添加商品个数,只需知道添加到服务器是否成功,不需要存储到start
        let result = await reqPostShopCart(skuId, skuNum)
        //使用async和await返回的一定是Promise
        if (result.code == 200) {
            //返回任意字符串表示成功
            return 'ok'
        } else {
            //失败的返回值
            return Promise.reject(new Error('filer'))
        }
    }
}
const mutations = {
    GETDETAIL(state, value) {
        state.detail = value
    }
}
const state = {
    detail: {}
}
const getters = {
    categoryView(state) {
        return state.detail.categoryView || {}
    },
    skuInfo(state) {
        return state.detail.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.detail.spuSaleAttrList || []
    }
}
export default {
    namespaced: true,// 开启命名空间
    actions, mutations, state, getters
}